package com.lanyou.cook.repository.userManagement;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

import com.lanyou.cook.entity.domain.userManagement.Role;

public interface RoleRepository extends Repository<Role, String>, JpaSpecificationExecutor<Role> {
	/*@RestResource(exported = true)
	Field findByName(@Param("name") String name);*/
	@RestResource(exported = false)
	Role findByRoleName(@Param("roleName") String roleName);
	
	
	long count();
	
	boolean exists(String id);
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"roleDelegation"})
	<S extends Role> S save(S entity);	// could expose REST API
	
	<S extends Role> List<S> save(Iterable<S> entities);
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"roleDelegation"})
	Role findOne(String id);	// could expose REST API
	
	Role getOne(String id);
	
	// 以下三个接口只能选一个暴露为REST API
	
	@RestResource(exported = false)
	List<Role> findAll();	// could expose REST API
	
	@RestResource(exported = false)
	List<Role> findAll(Sort sort);	// could expose REST API
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"roleDelegation"})
	Page<Role> findAll(Pageable pageable);	// could expose REST API
	
	List<Role> findAll(Iterable<String> ids);
	
	// 以下两个接口，要么都暴露为REST API，要么都不暴露
	@RestResource(exported = true)
	@RequiresPermissions(value={"roleDelegation"})
	void delete(String id);	// could expose REST API
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"roleDelegation"})
	void delete(Role entity);	// could expose REST API
	
	void delete(Iterable<? extends Role> entities);
	
	void deleteAll();
	
	void flush();
	
	<S extends Role> S saveAndFlush(S entity);
	
	void deleteInBatch(Iterable<Role> entities);
	
	void deleteAllInBatch();
}
